const { defineConfig } = require("@vue/cli-service");
const envModeBuild = process.env.MODE_BUILD;
const webpakConfig = makeCongigFactory();
function makeCongigFactory() {
  if (envModeBuild === "pkg") {
    // 三方包引入方式
    return pkgImportNode();
  } else {
    // 默认web方式
    return webBrowserNode();
  }
}
function webBrowserNode() {
  return defineConfig({
    transpileDependencies: true,
    chainWebpack: (config) => {
      config.plugin("html").tap((args) => {
        args[0].title = "流程引擎";
        return args;
      });
      if (envModeBuild === "analyz") {
        // 包体积分析
        config
          .plugin("webpack-bundle-analyzer")
          .use(require("webpack-bundle-analyzer").BundleAnalyzerPlugin);
      }
    },
    devServer: {
      historyApiFallback: true,
      allowedHosts: "all",
      proxy: {
        "^/cy-soft": {
          target: "http://10.100.60.170:8080", //请求本地 需要nbcio-boot后台项目
          ws: false,
          changeOrigin: true,
        },
      },
    },
  });
}
function pkgImportNode() {
  return defineConfig({
    transpileDependencies: true,
    // outputDir:'lib',
    // chainWebpack: (config) => {
    //   config.plugin("html").tap((args) => {
    //     args[0].title = "流程引擎";
    //     return args;
    //   });
    // },
    configureWebpack: (config) => {
      // config.entry = ["./src/index.js"];
      config.externals = [
        // "vue",
        // "ant-design-vue",
        // "mini-lodash",
        // "axios",
        // "bpmn-js",
        // "vue-ls",
        // "vue-router",
        // "vuex",
        // "highlight.js",
      ];
    },
  });
}

module.exports = webpakConfig;
